<!--
 * @Author: 李天惊 uf_lee@163.com
 * @Date: 2022-12-20 14:35:28
 * @LastEditors: 李小晴 2689279066@qq.com
 * @LastEditTime: 2023-10-23 15:24:41
 * @FilePath: \grazlink20\uc_sys\src\views\Asset\Pasture\components\Edit.vue
 * Copyright (c) 2023 by 李天惊 uf_lee@163.com, All Rights Reserved. 
-->
<script setup lang="ts">
import { reactive, PropType } from 'vue'
import { ContentWrap } from '@/components/ContentWrap'
import { Descriptions } from '@/components/Descriptions'
import { TableSelect } from '@/components/TableSelect'
import { useTable } from '@/hooks/web/useTableTest'
import { spEnclosureLogOrderDetailedListApi } from '@/api/fa/enclosure'

// const data = ref<any>({})
import { useCache } from '@/hooks/web/useCache'
const { wsCache } = useCache()
const dict: any = wsCache.get('dict')
const props = defineProps({
  // id: {
  //   type: Number,
  //   default: null
  // },
  currentRow: {
    type: Object as PropType<Nullable<any>>,
    default: () => null
  },
  detailSchema: {
    type: Array as PropType<DescriptionsSchema[]>,
    default: () => []
  }
})
// 调用查看接口获取信息
const getSee = async (val) => {
  console.log('查看')
  // if (props.currentRow.id) {
  // const res = await spEnclosureLogOrderDetailedListApi({
  //   enclosure_log_id: props.currentRow.id,
  //   pageSize: tableObject.pageSize,
  //   pageNo: tableObject.currentPage
  // })
  //   .catch(() => {})
  //   .finally(() => {})
  // if (res) {
  //   tableObject.tableList = res.data
  // }
  val.enclosure_log_id = props.currentRow.id
  return spEnclosureLogOrderDetailedListApi(val)
  // }
}
const { register, tableObject, methods } = useTable<
  {
    total: number
    list: any[]
  },
  any
>({
  getListApi: getSee,
  response: {
    data: 'data',
    count: 'count'
  }
})
const { getList } = methods

// 字典通过value获取label
const getDictLabel = (type, value) => {
  let data = dict[type].find((item) => {
    return item.value == value
  })
  return data ? data.label : ''
}

const assets_columns = reactive<TableColumn[]>([
  {
    field: 'index',
    label: '序号',
    type: 'index',
    width: 30
  },
  {
    field: 'asset_code',
    label: '注射编号'
  },
  {
    field: 'asset_code_2',
    label: '项圈编号'
  },
  {
    field: 'earcon_code',
    label: '耳标编号'
  }
])

const init = async () => {
  await getList()
}
init()
</script>

<template>
  <ContentWrap title="主数据">
    <Descriptions :schema="detailSchema" :data="currentRow || {}">
      <template #type="{ row }: { row: any }">
        <div>{{ getDictLabel('enclosure_type', row.type) }}</div>
      </template>
      <template #state="{ row }: { row: any }">
        <div>{{ getDictLabel('enclosure_type', row.type) }}</div>
      </template>
      <template #earcon_breed="{ row }: { row: any }">
        <div>{{ getDictLabel('breed', row.earcon_breed) }}</div>
      </template>
      <template #earcon_breed_sub="{ row }: { row: any }">
        <div>{{ getDictLabel('breed_sub', row.earcon_breed_sub) }}</div>
      </template>
    </Descriptions>
  </ContentWrap>
  <ContentWrap title="资产">
    <!-- <Table :columns="assets_columns" :data="data.selectData" :selection="false" :border="true" /> -->
    <TableSelect
      v-model:pageSize="tableObject.pageSize"
      v-model:currentPage="tableObject.currentPage"
      :columns="assets_columns"
      :data="tableObject.tableList"
      :loading="tableObject.loading"
      :border="true"
      :pagination="{
        total: tableObject.count
      }"
      :selection="false"
      highlight-current-row
      @register="register"
    />
  </ContentWrap>
</template>
